﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataAccessLogic;
using System.Data;

namespace BusinessLogic
{
    [Serializable]
    public class InstrumentType : CodeTable<InstrumentType>
    {
        #region Methods
        public InstrumentType()
        {
            _id = Guid.Empty;
        }

        public override void Create()
        {
            InstrumentTypeDataAccess.Create(this);
        }

        public override void Delete()
        {
            InstrumentTypeDataAccess.Delete(this);
        }

        protected override List<InstrumentType> ProtectedGetAll()
        {
            DataTable dt = InstrumentTypeDataAccess.GetAll();
            List<InstrumentType> codeTables = null;

            if ((dt != null) && (0 < dt.Rows.Count))
            {
                codeTables = new List<InstrumentType>();

                foreach (DataRow row in dt.Rows)
                {
                    codeTables.Add(InstrumentTypeDataAccess.BindDataToInstrumentType(row));
                }
            }

            return codeTables;
        }

        protected override InstrumentType ProtectedGetByID(Guid id)
        {
            DataRow row = InstrumentTypeDataAccess.GetByID(id);

            if (row != null)
            {
                return InstrumentTypeDataAccess.BindDataToInstrumentType(row);
            }

            return null;
        }

        public void FillByID()
        {
            if(this._id != Guid.Empty)
            {
                InstrumentType it = ProtectedGetByID(this._id);
                this.Description = it.Description;
            }
        }

        public override void Update()
        {
            InstrumentTypeDataAccess.Update(this);
        }
        #endregion

        #region Properties
        public override string CacheKeyName
        {
            get
            {
                return SEPDefaults.CacheKeyNames.INSTRUMENTTYPES;
            }
        }
        #endregion
    }
}